function mergeSort(array, start, end) {
    let mid = Math.floor((start + end) / 2);
    if (start < end) {
        mergeSort(array, start, mid); //分治法 左边的进行归并排序
        mergeSort(array, mid + 1, end); //右边的进行归并排序
        merge(array, start, mid, end);
    }
}

function merge(array, start, mid, end) {
    let i = start,
        j = mid + 1,
        arr = [];
    while (i <= mid && j <= end) {
        if (array[i] < array[j]) {
            arr.push(array[i++]);
        } else {
            arr.push(array[j++]);
        }
    }
    while (i <= mid) {
        arr.push(array[i++]);
    }
    while (j <= end) {
        arr.push(array[j++]);
    }
    for (let k = start; k <= end; k++) {
        array[k] = arr[k - start];
    }
}
let array = [23, 4, 12, 8, 5, 26, 3, 4, 1];
mergeSort(array, 0, array.length - 1);
console.log(array); //[1,3,4,4,5,8,12,23,26]